package com.sphd.education.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.sphd.education.R;
import com.sphd.education.activitys.ImageShowActivity;
import com.sphd.education.activitys.TeacherIntroduceActivity;
import com.sphd.education.info.SchoolTeacherImgInfo;
import com.sphd.education.modle.EducationUrl;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by HU on 2016/1/4.
 */
public class ImageShowLessonAdapter extends BaseAdapter {
    Context context;
    List<SchoolTeacherImgInfo> list;
    public ImageShowLessonAdapter(Context context, List<SchoolTeacherImgInfo> list) {
        this.context=context;
        this.list=list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_image_show, null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        ImageLoader.getInstance().displayImage(EducationUrl.HttpTitle + "/" + list.get(position).getTeacher_img_url(),  viewHolder.myImage);
        viewHolder.tvName.setText(list.get(position).getTeacher_name());
        viewHolder.imageLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, TeacherIntroduceActivity.class);
                intent.putExtra("SchoolTeacherImgInfo",list.get(position));
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.my_image)
        ImageView myImage;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.image_layout)
        RelativeLayout imageLayout;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
